package www.admin.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import www.admin.dao.IGroupResourceDao;
import www.admin.dao.ISysRoleDao;
import www.admin.model.SysRole;
import www.admin.mybatis.Criteria;
import www.admin.service.ISysRoleService;
import www.admin.utils.Layui;
import www.admin.utils.MessageConstant;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;


@Service
public class SysRoleServiceImpl implements ISysRoleService{


	/**
	 *分页查询 
	 * 
	 **/
	public Layui queryPage (Criteria<SysRole> param){
		PageHelper.startPage(param.getStartIndex(), param.getPageSize());
		List<SysRole> list = sysRoleRepository.queryPage(param);
		PageInfo<SysRole> paInfo = new PageInfo<SysRole>(list);
	    return Layui.data((int)paInfo.getTotal(), paInfo.getList());
	}

	/**
	 * 分页总数查询
	 * 
	 **/
	public Integer queryPageCount (Criteria<SysRole> param){
		return (Integer) sysRoleRepository.queryPageCount(param);
	}

	/**
	 * 查询（根据主键ID查询）
	 * 
	 **/
	public SysRole  queryEntity (String id ){
		return sysRoleRepository.queryEntity(id);
	}

	/**
	 *  删除（根据主键ID删除）
	 * 
	 **/
	public String deleteById (String id ){
		int result = sysRoleRepository.deleteById(id);
			if ( result != 1) {
					return MessageConstant.USER_TYPE_18;
			}
			return null;
	}

	/**
	 * 添加 （匹配有值的字段）
	 * 
	 **/
	public String insert(SysRole record ){
		int result = sysRoleRepository.insert(record);
			if ( result != 1) { 
					return MessageConstant.USER_TYPE_13;
			}
			return null;
	}

	/**
	 * 修改（匹配有值的字段）
	 * 
	 **/
	public String update (Criteria<SysRole> param){
		int result = sysRoleRepository.update(param);
			if ( result != 1) { 
					return MessageConstant.USER_TYPE_17;
			}
			return null;
	}
	
	/**
	 * 删除（根据USERID删除）
	 * 
	 **/
	@Override
	public SysRole queryByRoleKey(String userId) {
		return sysRoleRepository.queryByRoleKey(userId);
	}
	
	/**
	 * 列表list)
	 * 
	 */
	@Override
	public List<SysRole> queryPageList(Criteria<SysRole> param) {
		return sysRoleRepository.queryPage(param);
	}

	/**
	 * 查询(根据roleName查询)
	 * 
	 */
	@Override
	public SysRole queryByName(String roleName) {
		return sysRoleRepository.queryByName(roleName);
	}

	@Resource
	private ISysRoleDao sysRoleRepository;
	
	@Resource
	private IGroupResourceDao groupResourceDao;

}